//
//  FundManagementVC.m
//  优学荟管理系统
//
//  Created by 星道 on 17/9/5.
//  Copyright © 2017年 星道三好. All rights reserved.
//

#import "FundManagementVC.h"
#import "FundManagementModel.h"
#import "FundManagementCell.h"
#import "FundManagementSubCell.h"
#import "HNSNGetMoneyVC.h"
#import "FundManagementRecordVC.h"
#import "ZYSegmentController.h"
#import "ZYResourceCircleTowController.h"
#import "ZYStarSegmentController.h"
@interface FundManagementVC ()<UITableViewDelegate,UITableViewDataSource>
{
    IBOutlet UITableView *_tableView;

}
@property (strong, nonatomic) NSMutableArray <FundManagementModel *>*dataArr;
@end

@implementation FundManagementVC



#pragma mark - life cycle
- (void)viewDidLoad {

    [super viewDidLoad];

    self.title = @"资金管理";
    [_tableView registerNib:[UINib nibWithNibName:[FundManagementCell description] bundle:nil] forCellReuseIdentifier:@"cell"];
    [_tableView registerNib:[UINib nibWithNibName:[FundManagementSubCell description] bundle:nil] forCellReuseIdentifier:@"subCell"];
}









#pragma mark - 表单数据
- (NSArray *)TitleArr {

    return @[@"资金提现", @"星币提现", @"提现记录", @"绩效补贴"];
}

- (NSArray *)MoneyArr {

    return @[@"课程提现", @"套餐提现", @"课时卡提现", @"加强课提现"];
}

- (NSArray *)CoinsArr {

    return @[@"课程抵扣提现", @"佣金提现", @"平台补贴"];
}

- (NSArray *)RecordArr {

    return @[@"资金提现记录", @"星币提现记录"];
}

- (NSArray *)Arr {

    return @[[self MoneyArr], [self CoinsArr], [self RecordArr],@[]];
}





#pragma makr - tableView delegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    return self.dataArr.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    FundManagementModel *model = self.dataArr[section];
    return model.isShow ? model.arr.count+1 : 1;

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    FundManagementModel *model = self.dataArr[indexPath.section];
    // 抽屉头

    if (indexPath.row == 0) {

        FundManagementCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
        cell.model = model;
        return cell;

    } else {

        FundManagementSubCell *cell = [tableView dequeueReusableCellWithIdentifier:@"subCell" forIndexPath:indexPath];
        cell.subTitle = model.arr[indexPath.row - 1];
        return cell;
    }
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    FundManagementModel *model = self.dataArr[indexPath.section];
    if ([model.title isEqualToString:@"绩效补贴"]) {
        
        [self ResourceCircleTow];
        
    } else {
    if (indexPath.row == 0) {
        // 打开关闭抽屉
        model.isShow = !model.isShow;
        [tableView reloadSections:[NSIndexSet indexSetWithIndex:indexPath.section] withRowAnimation:(UITableViewRowAnimationAutomatic)];

    } else {

        switch (indexPath.section) {
            case 0:
                [self MoneyWithIndex:indexPath.row-1 arr:model.arr];
                break;
            case 1:
                [self CoinsWithIndex:indexPath.row-1 arr:model.arr];
                break;
            case 2:
                [self RecordWithIndex:indexPath.row-1 arr:model.arr];
                break;
            default:
                break;
        }
    }
    }
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {

    return indexPath.row == 0 ? 64:44;
}








#pragma mark - 资金提现_点击
- (void)MoneyWithIndex:(NSInteger)index arr:(NSArray <NSString *>*)arr {

    // 资金提现操作
    // 课程提现
    HNSNGetMoneyVC *VC = [[HNSNGetMoneyVC alloc] init];
    [self.navigationController pushViewController:VC animated:YES];

    // 标志身份 普通机构
    if (index == 0) {

        VC.title = @"课程提现";
        VC.HNSNGetMoneyType = HNSNGetMoneyTypeNormalZiJin;
    } else if (index == 1) {

        VC.title = @"套餐提现";
        VC.HNSNGetMoneyType = HNSNGetMoneyTypeNormalTaoCan;
    } else if (index == 2 ) {

        VC.title = @"课时卡提现";
        VC.HNSNGetMoneyType = HNSNGetMoneyTypeNormalKeShiKa;
    } else {
        
        VC.title = @"加课课提现";
        VC.HNSNGetMoneyType = HNSNGetMoneyTypeNormalStrongCourse;
    }
}










#pragma mark - 星币提现_点击
- (void)CoinsWithIndex:(NSInteger)index arr:(NSArray <NSString *>*)arr {

    // 星币提现操作
    if (index != 2)
    {
        HNSNGetMoneyVC *VC = [[HNSNGetMoneyVC alloc] init];
        [self.navigationController pushViewController:VC animated:YES];

        if (index == 0) {

            VC.title = @"课程抵扣提现";
            VC.HNSNGetMoneyType = HNSNGetMoneyTypeNormalXingBi;
        } else if (index == 1) {

            VC.title = @"佣金提现";
            VC.HNSNGetMoneyType = HNSNGetMoneyTypeNormalKeYongJin;
        }
    } else
    {
        [HUD showSuccess:@"功能即将开启，敬请期待"];
    }
}






#pragma mark - 提现记录_点击
- (void)RecordWithIndex:(NSInteger)index arr:(NSArray <NSString *>*)arr {


    if (0 == index) {
        // 提现记录点击
        ZYSegmentController *VC = [[ZYSegmentController alloc] init];
  
        [self.navigationController pushViewController:VC animated:YES];
    }else if (1 == index){
        // 提现记录点击
        ZYStarSegmentController *VC = [[ZYStarSegmentController alloc] init];

        [self.navigationController pushViewController:VC animated:YES];
    }

//缩短到达终极文明进度，借助智慧的力量

}



#pragma mark - 绩效补贴_点击
- (void)ResourceCircleTow {
    
    ZYResourceCircleTowController *VC = [[ZYResourceCircleTowController alloc] init];
    [self.navigationController pushViewController:VC animated:YES];
}







#pragma mark - getter
- (NSMutableArray<FundManagementModel *> *)dataArr {

    if (!_dataArr) {

        _dataArr = [NSMutableArray array];
        [[self TitleArr] enumerateObjectsUsingBlock:^(NSString * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            
            FundManagementModel *model = [FundManagementModel HNObjectForTitle:obj arr:[self Arr][idx]];
            [_dataArr addObject:model];
        }];
        
    }
    return _dataArr;
}
@end
